﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;

namespace Web
{
    public partial class Login : System.Web.UI.Page
    {
        /// <summary>
        /// 初始化页面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//判断是否为第一次加载
            {
                //错误提示区域隐藏
                this.userError.Visible = false;
                
            }
        }

        /// <summary>
        /// 登录验证
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void loginin(object sender, EventArgs e)
        {
            Model.Model_UserInfo user = new Model.Model_UserInfo
            {
                username = Regex.Replace(this.username.Value,@"[^\w\.\/]",""),
                password = Regex.Replace(this.password.Value, @"[^\w\.\/]", "")
            };

            bool check = BLL.BLL_UserInfo.Check(user);
            if (check)
            {
                Session["username"] = user.username;
                Response.Redirect("index.aspx");
            }
            else
            {
                //显示错误信息
                this.userError.Visible = true;
            }
        }
    }
}